<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const adaptiveCard = {
          content: {
            type: 'AdaptiveCard',
            $schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
            version: '1.5',
            actions: [{ type: 'Action.Submit', title: 'Button' }]
          },
          contentType: 'application/vnd.microsoft.card.adaptive'
        };

        const { directLine, store } = testHelpers.createDirectLineEmulator();

        WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat'));

        await pageConditions.uiConnected();

        await directLine.emulateIncomingActivity({
          attachments: [adaptiveCard],
          id: 'a-00001',
          text: 'Hello, World!',
          type: 'message'
        });

        await pageConditions.numActivitiesShown(1);

        expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Hello, World!');

        const pushButton1 = document.querySelector('.ac-pushButton');

        pushButton1.focus();

        expect(document.activeElement).toBe(pushButton1);

        // Modifying "adaptiveCardsHostConfig" props will cause the Adaptive Card to be re-rendered.
        WebChat.renderWebChat({ adaptiveCardsHostConfig: {}, directLine, store }, document.getElementById('webchat'));

        await directLine.emulateIncomingActivity({
          attachments: [adaptiveCard],
          id: 'a-00001',
          text: 'Aloha!',
          type: 'message'
        });

        expect(pageElements.activityContents()[0]).toHaveProperty('textContent', 'Aloha!');

        const pushButton2 = document.querySelector('.ac-pushButton');

        expect(document.activeElement).toBe(pushButton2);
      });
    </script>
  </body>
</html>
